<?php
/**
* @version $Id: frontendxml.php 5930 2007-12-30
* @package jootaX
* @copyright Copyright (C) 2007
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

defined( '_VALID_MOS' ) or die( 'Restricted access' );
/**
* @param string The position
* @param int The style.  0=normal, 1=horiz, -1=no wrapper
*/
function mosLoadModulesXML( $position='left', $style=0 ) {
	global $mosConfig_gzip, $mosConfig_absolute_path, $database, $my, $Itemid, $mosConfig_caching;

	$tp = intval( mosGetParam( $_GET, 'tp', 0 ) );
	if ($tp) {
		echo '<div style="height:50px;background-color:#eee;margin:2px;padding:10px;border:1px solid #f00;color:#700;">';
		echo $position;
		echo '</div>';
		return;
	}
	$style = intval( $style );
	$cache =& mosCache::getCache( 'com_content' );

	require_once( $mosConfig_absolute_path . '/includes/frontendxml.html.php' );

	$allModules =& initModules();
	if (isset( $GLOBALS['_MOS_MODULES'][$position] )) {
		$modules = $GLOBALS['_MOS_MODULES'][$position];
	} else {
		$modules = array();
	}

	if (count( $modules ) < 1) {
		$style = 0;
	}
	if ($style == 1) {
		echo "<table cellspacing=\"1\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
		echo "<tr>\n";
	}
	$prepend = ($style == 1) ? "<td valign=\"top\">\n" : '';
	$postpend = ($style == 1) ? "</td>\n" : '';

	$count = 1;
	foreach ($modules as $module) {
		$params = new mosParameters( $module->params );

		echo $prepend;

		if ((substr("$module->module",0,4))=='mod_') {
		// normal modules
			if ($params->get('cache') == 1 && $mosConfig_caching == 1) {
			// module caching
				$cache->call('modules_xml::module2', $module, $params, $Itemid, $style, $my->gid  );
			} else {
				modules_xml::module2( $module, $params, $Itemid, $style, $count );
			}
		} else {
		// custom or new modules
			if ($params->get('cache') == 1 && $mosConfig_caching == 1) {
			// module caching
				$cache->call('modules_xml::module', $module, $params, $Itemid, $style, 0, $my->gid );
			} else {
				modules_xml::module( $module, $params, $Itemid, $style );
			}
		}

		echo $postpend;

		$count++;
	}
	if ($style == 1) {
		echo "</tr>\n</table>\n";
	}
}

// Utilities to write XML info 
function writeXMLNode ($name, $content){
	echo '<'. $name. '>'.$content.'</'.$name.'>'.chr(10);
}
function writeXMLEndNode($name){
	echo '</'.$name.'>'.chr(10);
}
function writeXMLStartNode($name){
	echo '<'.$name.'>',chr(10);
}